﻿using System;
using System.ComponentModel;
using System.Linq.Expressions;
using HelloWorld.Code.DataAccess;
using HelloWorld.Models.BaseListViewModel;

namespace HelloWorld.Models
{
    public class UsersList : ListViewModel<User>
    {
        #region Filters

        [DisplayName("First name")]
        [ListViewFilter("fn")]
        public string FirstName { get; set; }

        [DisplayName("Last name")]
        [ListViewFilter("ln")]
        public string LastName { get; set; }

        public override Expression<Func<User, bool>> FilterCondition
        {
            get
            {
                return
                    (u =>
                     (string.IsNullOrEmpty(FirstName) || u.FirstName.Contains(FirstName.Trim())) &&
                     (string.IsNullOrEmpty(LastName) || u.LastName.Contains(LastName.Trim())));
            }
            set { }
        }

        #endregion

        public UsersList()
        {
            var unitOfWork = new UnitOfWork();
            Repository = unitOfWork.GetUserRepository;            
            IncludeList.Add("UserRole");
            PageSize = 5;
        }
    }
}